﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Xml;
using Tencent;
using Newtonsoft.Json;
using BrnMall.WeiXin.Sdk.Domain;

namespace BrnMall.WeiXin.Sdk.Work
{
    public class SuiteTicketHelper
    {

        public static Tuple<string, string> GetTicketInfo(string xmlData)
        {
            string SuiteId = string.Empty;      //第三方应用的SuiteId
            string suite_ticket = string.Empty;
            XmlDocument xml = new XmlDocument();
            try
            {
                xml.LoadXml(xmlData);
                if (xml.GetElementsByTagName("SuiteTicket").Count > 0)
                    suite_ticket = xml.GetElementsByTagName("SuiteTicket")[0].InnerText;

                if (xml.GetElementsByTagName("SuiteId").Count > 0)
                    SuiteId = xml.GetElementsByTagName("SuiteId")[0].InnerText;
            }
            catch (Exception ex) { }

            return Tuple.Create(SuiteId, suite_ticket);
        }

        /// <summary>
        /// 从xml文档中提取suite_ticket
        /// </summary>
        public static string GetInfoType(string xmlData)
        {
            string suite_ticket = string.Empty;
            XmlDocument xml = new XmlDocument();
            try
            {
                xml.LoadXml(xmlData);
                if (xml.GetElementsByTagName("InfoType").Count > 0)
                    suite_ticket = xml.GetElementsByTagName("InfoType")[0].InnerText;
            }
            catch (Exception ex) { Log("xml解析错误:" + ex.Message); }

            return suite_ticket;
        }


        static void Log(string str)
        {
        }

    }
}